﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PM.Entity;
using PM.Services;

namespace PM.Site.Admin
{
    public partial class BonusRightReceivables : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] == null || Session["UserTypeId"] == null)
            {
                Response.Redirect("Login.aspx?RequestUrl=" + Request.Url.OriginalString);
            }
            else if (Session["UserTypeId"] != null)
            {
                if (Int32.Parse(Session["UserTypeId"].ToString()) == 1)
                {
                    this.Loading();
                }
                else
                {
                    Response.Redirect("Default.aspx?RequestUrl=" + Request.Url.OriginalString);
                }

            }
            else
            {
                Response.Redirect("Default.aspx?RequestUrl=" + Request.Url.OriginalString);
            }

        }

        private void Loading()
        {

            if (!Page.IsPostBack)
            {
                ddlClientIds.DataSource = ClientServices.GetClientID_Name_Collection();
                ddlClientIds.DataTextField = "Other_Names";
                ddlClientIds.DataValueField = "ClientId";
                ddlClientIds.AppendDataBoundItems = true;
                ddlClientIds.DataBind();

                dlBonusIssues.DataSource = DividendServices.Get_Bonus_Issue_Receivable_Collection();
                dlBonusIssues.DataBind();
               
                dlRights.DataSource = DividendServices.Get_Rights_Issue_Receivable_Collection();
                dlRights.DataBind();

            }
        }

        protected void btnApplyDividends_Click(object sender, EventArgs e)
        {
            DividendServices.AddDividendReceivables();
            Response.Redirect("~/Admin/DividendReceivables.aspx");           

        }

        protected void ddlClientIds_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlClientIds.SelectedValue != string.Empty)
            {
                dlBonusIssues.DataSource = DividendServices.Get_Bonus_Receivable_Collection_By_ClientId(ddlClientIds.SelectedValue);
                dlBonusIssues.DataBind();

                dlRights.DataSource = DividendServices.Get_Rights_Receivable_Collection_By_ClientId(ddlClientIds.SelectedValue);
                dlRights.DataBind();
            }
            else
            {
                dlBonusIssues.DataSource = DividendServices.Get_Bonus_Issue_Receivable_Collection();
                dlBonusIssues.DataBind();

                dlRights.DataSource = DividendServices.Get_Rights_Issue_Receivable_Collection();
                dlRights.DataBind();
            }
        }
       
    }
}
